package com.dqyt.app.controller;

import com.alibaba.fastjson.JSON;
import com.dqyt.app.service.AppUserService;
import com.dqyt.khjc.bean.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class AppUserController {

    @Autowired
    private AppUserService userService;

    /**
     * 查询某个角色的所有用户
     * @param request
     * @param role
     * @return
     */
    @RequestMapping(value = "/sample/getUserByRole")
    public String getUserByRole(HttpServletRequest request, long userId, String token, long role){
        return JSON.toJSONString(userService.getUserByRole(request, userId, token, role));
    }

    /**
     * 查询自己信息
     * @param request
     * @return
     */
    @RequestMapping(value = "/sample/getUserByIpApp")
    public String getUserByIpApp(HttpServletRequest request, long userId, String token){
        return JSON.toJSONString(userService.getUserByIpApp(request, userId, token));
    }


    /**
     * 查询所有用户
     * @param request
     * @return
     */
    @RequestMapping(value = "/sample/getUserALL")
    public String getUserALL(HttpServletRequest request, long userId, String token){
        return JSON.toJSONString(userService.getUserALL(request, userId, token));
    }


    /**
     * 修改密码
     *
     * @param request
     * @param oldPassword
     * @param newPassword
     * @param newPassword2
     * @return
     */
    @RequestMapping(value = "/sample/updatePassword", method = {RequestMethod.POST})
    public ResultMsg updatePwd(HttpServletRequest request,long userId, String token, String oldPassword, String newPassword, String newPassword2) {
        ResultMsg resultMsg = userService.updatePwd(request,userId,token, oldPassword, newPassword, newPassword2);
        return resultMsg;
    }



    /**
     * 分页获取我的印章列表
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/sample/getMyseaAll", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultMsg getMyseaAll(HttpServletRequest request,long userId, String token) {
        ResultMsg resultMsg = userService.getMyseaAll(request, userId, token);
        return resultMsg;
    }


    /**
     * 设置印章启用和禁用
     *
     * @param request
     * @param sealId
     * @return
     */
    @RequestMapping(value = "/sample/updateUserBySeal", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultMsg setSealType(HttpServletRequest request,long userId, String token, long sealId) {
        ResultMsg resultMsg = userService.setSealType(request,userId,token,sealId);
        return resultMsg;
    }



    /**
     * 查询某个角色的所有用户
     *
     * @param request
     * @param role
     * @return
     */
    @RequestMapping(value = "/sample/getUserByRoleForList", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultMsg getUserByRoleForWork(HttpServletRequest request,long userId, String token, long role) {
        ResultMsg resultMsg = userService.getUserByRoleForWork(request,userId,token, role);
        return resultMsg;
    }



    /**
     * 查询某个角色的用户  包含印章信息
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/sample/getUserListJc", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultMsg getUserListJc(HttpServletRequest request,long userId, String token, String role) {
        ResultMsg resultMsg = userService.getUserListJc(request,userId,token ,role);
        return resultMsg;
    }




    /**
     * 查询用户
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/sample/getLoginByUserId", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultMsg getLoginByUserId(HttpServletRequest request,long userId, String token) {
        ResultMsg resultMsg = userService.getLoginByUserId(request,userId,token);
        return resultMsg;
    }







    /**
     * 查询某个角色的用户  包含印章信息
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/sample/getAppUserListJcLhq", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultMsg getAppUserListJcLhq(HttpServletRequest request,long userId, String token, String role) {
        ResultMsg resultMsg = userService.getAppUserListJcLhq(request,userId,token ,role);
        return resultMsg;
    }


}
